/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package contextManagement;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

/**
 *
 * @author huangqing
 */
public class TimeGoesOn implements Runnable, PropertyChangeListener{
   private boolean continuer = false ;
   private int DELTAT = 3000;
   private ContextBroker cb;
   private Thread thread;

   public TimeGoesOn (ContextBroker cb){
        this.cb = cb;
        this.cb.addPropertyChangeListener("mort",this);
        continuer = true;
	thread = new Thread(this, "TimeGoesOn");
	thread.start();
        
   }


    public void arreter() {
        continuer = false;
    }

    public void propertyChange(PropertyChangeEvent pce) {
	String property = pce.getPropertyName();
	if (property.equals("mort"))
		arreter();
    }


    public void run() {
            try{
		while(continuer){
                    cb.firePropertyChange(new PropertyChangeEvent(this, "deltat", Boolean.valueOf(!continuer), Boolean.valueOf(continuer)));
                    Thread.sleep(DELTAT);
		}
            } catch (Exception e){}
	}

}




